package org.jeecg.modules.reserve.utils;

import javafx.geometry.Point2D;
/**
 * 经纬度
 */

public class LocationUtil {
    private static final double EARTH_RADIUS = 6371393;
    // 平均半径,单位：m
    // /*** 通过AB点经纬度获取距离** @param pointA A点(经，纬)* @param pointB B点(经，纬)* @return 距离(单位：米)*/
    public static double getDistance(Point2D pointA, Point2D pointB)
    {
        // 经纬度（⻆度）转弧度。弧度用作参数，以调用Math.cos和Math.sin
        double radiansAX = Math.toRadians(pointA.getX());
        // A经弧度
        double radiansAY = Math.toRadians(pointA.getY());
        // A纬弧度
        double radiansBX = Math.toRadians(pointB.getX());
        // B经弧度
        double radiansBY = Math.toRadians(pointB.getY());
        // B纬弧度// 公式中“cosβ1cosβ2cos（α1-α2）+sinβ1sinβ2”的部分，得到∠AOB的cos值
        double cos = Math.cos(radiansAY) * Math.cos(radiansBY) * Math.cos(radiansAX - radiansBX) + Math.sin(radiansAY) * Math.sin(radiansBY);
        double acos = Math.acos(cos);
        // 反余弦值
        return EARTH_RADIUS * acos;
        // 最终结果
    }
    public static void main(String[]args){
        // 正校⻔口
        Point2D pointDD = new Point2D(103.893134, 30.792867);
        // 文澄楼 2314
        Point2D pointXD = new Point2D(103.88469, 30.790163);
        System.out.println(getDistance(pointDD, pointXD));
        System.out.println();
    }
}
